package com.huyaanalysisplatform.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.huyaanalysisplatform.entity.TLiveCount;
import com.huyaanalysisplatform.entity.TLolHotHero;
import com.huyaanalysisplatform.entity.TTop10Anchor;
import com.huyaanalysisplatform.mapper.TLolHotHeroMapper;
import com.huyaanalysisplatform.service.TLolHotHeroService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.stereotype.Service;

import java.util.*;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author Huadi Group 12
 * @since 2021-08-01
 */
@Service
public class TLolHotHeroServiceImpl extends ServiceImpl<TLolHotHeroMapper, TLolHotHero> implements TLolHotHeroService {

    public Map queryAll() {
        List<TLolHotHero> tableData = this.list();
        Map map = new HashMap();
        map.put("tableData", tableData);
        return map;
    }

    public Map addHotHero(TLolHotHero tLolHotHero) {
        Map map = new HashMap();
        map.put("heroName", tLolHotHero.getHeroName());
        List<TLolHotHero> tLolHotHeroes = this.listByMap(map);

        if (CollectionUtils.isNotEmpty(tLolHotHeroes)) {
            map.put("code", "1");
            map.put("message", "英雄已存在");
            return map;
        }

        if (this.save(tLolHotHero)) {
            map.put("code", 0);
            map.put("message", "成功");
            return map;
        } else {
            map.put("code", 1);
            map.put("message", "添加失败");
            return map;
        }
    }

    public Map editHotHero(TLolHotHero tLolHotHero) {
        Map map = new HashMap();
        QueryWrapper<TLolHotHero> queryWrapper = new QueryWrapper<TLolHotHero>()
                .notIn("id", tLolHotHero.getId())
                .eq("heroName", tLolHotHero.getHeroName());
        List<TLolHotHero> tLolHotHeroes = this.list(queryWrapper);
        if (CollectionUtils.isNotEmpty(tLolHotHeroes)) {
            map.put("code", 1);
            map.put("message", "英雄名称已存在");
            return map;
        }
        if (this.updateById(tLolHotHero)) {
            map.put("code", 0);
            map.put("message", "成功");
            return map;
        } else {
            map.put("code", 1);
            map.put("message", "修改失败");
            return map;
        }
    }

    public Map deleteHotHero(String id){
        if (this.removeById(id)) {
            Map map = new HashMap();
            map.put("code", 0);
            map.put("message", "成功");
            return map;
        } else {
            Map map = new HashMap();
            map.put("code", 1);
            map.put("message", "添加失败");
            return map;
        }
    }


}
